﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.Windows.Data;
using System.Diagnostics;

namespace RStein.PosterousReader.WP.Behaviors
{
  public class PasswordTextChangedBehavior : TextChangedBehaviorBase<PasswordBox>
  {
    public PasswordTextChangedBehavior()
    {
    }



    protected override void OnAttached()
    {
      base.OnAttached();
      if (AssociatedObject != null)
      {
        AssociatedObject.PasswordChanged += AssociatedObject_TextChanged;
      }
    }

    protected override void OnDetaching()
    {
      AssociatedObject.PasswordChanged -= AssociatedObject_TextChanged;

    }

    void AssociatedObject_TextChanged(object sender, RoutedEventArgs e)
    {
      UpdateSource();
      RunTextChangedAction();
    }

    public override BindingExpression GetBindingExpression(PasswordBox passwordBox)
    {
      if (passwordBox == null)
      {
        return null;
      }

      return passwordBox.GetBindingExpression(PasswordBox.PasswordProperty);
    }


  }
}
